# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=wxhexeditor
pkgver=733.f439d8f
pkgrel=5
pkgdesc='A free hex editor / disk editor for Linux, Windows and MacOSX.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-binary' 'blackarch-misc')
url='http://wxhexeditor.sourceforge.net/'
license=('GPL')
depends=('wxwidgets-gtk3' 'mhash' 'python' 'python2' 'gcc-libs')
makedepends=('git' 'python' 'python2')
source=("$pkgname::git+https://github.com/EUA/wxHexEditor.git"
        'Makefile.patch')
sha512sums=('SKIP'
            'fb232202b23a02ff2b5e11b91e3c067540f0ce698ae338a9478e7541ca49bfb43796d34c357b742ebd0c6280483c83939072e465a5c0f9bd0df8f9bf80e5fae4')

pkgver() {
  cd $pkgname

  echo "$(git rev-list --count HEAD)"."$(git rev-parse --short HEAD)"
}

prepare() {
  cd $pkgname

  patch -Np2 -i "$srcdir/Makefile.patch"
}

build() {
  cd $pkgname

  export CFLAGS="-O2 -Wall -Wno-error -Wno-implicit-function-declaration -std=gnu89"
  export CXXFLAGS="${CXXFLAGS} -O2 -Wall -Wno-error -Wno-implicit-function-declaration -std=gnu89"

  if [[ $CARCH == "aarch64" ]]; then
    export CC="gcc"
    export CXX="g++"
    export HOST="aarch64-linux-gnu"
    export CHOST="aarch64-linux-gnu"
    export CBUILD="aarch64-linux-gnu"
    export CFLAGS+=" -march=armv8-a"
    export CXXFLAGS+=" -march=armv8-a"
  fi

  make -s WXCONFIG='/usr/bin/wx-config' CXXFLAGS="${CXXFLAGS/-fno-rtti/}"
}

package() {
  cd $pkgname

  make DESTDIR="$pkgdir" PREFIX="/usr" install

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" docs/*
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

